#include "PAP_defs.h"
#include "derivative.h"
#include "Services.h"
#include "TPM_HAL_GB.h"

#define LCD_DATA_7  PTBD_PTBD3
#define LCD_DATA_6  PTBD_PTBD2
#define LCD_DATA_5  PTBD_PTBD1
#define LCD_DATA_4  PTBD_PTBD0

#define LCD_DATA_7_DD  PTBDD_PTBDD3
#define LCD_DATA_6_DD  PTBDD_PTBDD2
#define LCD_DATA_5_DD  PTBDD_PTBDD1 
#define LCD_DATA_4_DD  PTBDD_PTBDD0

#define LCD_MODE    PTCD_PTCD7
#define LCD_EN_1    PTAD_PTAD6
#define LCD_EN_2    PTAD_PTAD0

#define LCD_RS_DD   PTCDD_PTCDD7
#define LCD_EN_1_DD PTADD_PTADD6
#define LCD_EN_2_DD PTADD_PTADD0

#define LCD_BACKLIGHT_CHANNEL   0

#define LCD_INSTRUCTION 0
#define LCD_DATA_MODE   1

#define LCD_DISPLAY_ONLY_1  0x01
#define LCD_DISPLAY_ONLY_2  0x02
#define LCD_DISPLAY_BOTH    0x03  

#define LCD_DIR_N 0x00
#define LCD_DIR_S 0x02
#define LCD_DIR_E 0x04
#define LCD_DIR_W 0x08

#define LCD_DIR_NE 0x10
#define LCD_DIR_NW 0x20
#define LCD_DIR_SE 0x40
#define LCD_DIR_SW 0x80
                     
#define DELAY_40US   6
#define DELAY_100US  14
#define DELAY_2MS    251
#define DELAY_1MS    126

#define ENABLED     1
#define DISABLED    0

#define LCD_INIT_CURSOR      DISABLED
#define LCD_INIT_BLINKING    DISABLED

#define LCD_INIT_CURSOR_BLINKING ( 0x0C | LCD_INIT_CURSOR<<1 | LCD_INIT_BLINKING)

#define LCD_BLINKING     0x0D
#define LCD_NOT_BLINKING 0x0C

#define LCD_SYM_SIGNAL		0x00
#define LCD_SYM_BATTERY		0x01
#define LCD_SYM_MENU		0x02
#define LCD_SYM_MOTOR		0x03
#define LCD_SYM_DRIVER		0x04
#define LCD_SYM_GPS			0x05
#define LCD_SYM_ULTRASONIC	0x06
#define LCD_SYM_HBLED		0x07


#define LCD_SEND_CLOCK()     \
if (u8lcd & 0x01)            \
{                            \
    LCD_EN_1 ^= 1;           \
    LCD_EN_1 ^= 1;           \
}                            \
if (u8lcd & 0x02)            \
{                            \
    LCD_EN_2 ^= 1;           \
    LCD_EN_2 ^= 1;           \
}


void vfnLCD_Delay (uint8 u8delay);

void vfnLCD_SendData (uint8 u8lcd, uint8 u8data);

void vfnLCD_Init (uint8 u8lcd);

void vfnLCD_InitMessage(void);

void vfnLCD_GPIO_Init (void);

void vfnLCD_SendLine (uint8 u8line, uint8 *u8string);

void vfnLCD_setBlinking(uint8 u8line, uint8 u8mode);

void vfnLCD_putBuffer1(uint8 *u8string);
void vfnLCD_putBuffer2(uint8 *u8string);
void vfnLCD_putBuffer3(uint8 *u8string);
void vfnLCD_putBuffer4(uint8 *u8string);

void vfn_LCD_MenuSelLine(uint8 u8line);